package com.keqiang.chart.impl.radar

import android.graphics.Color
import android.graphics.PathEffect
import androidx.annotation.ColorInt
import androidx.annotation.FloatRange
import androidx.annotation.IntRange
import androidx.annotation.Px
import com.keqiang.chart.utils.px

/**
 * 配置轴相关数据
 *
 * @author Created by wanggaowan on 2022/7/20 10:12
 */
open class Axis {
    /**
     * 轴线的颜色
     */
    @setparam:ColorInt
    open var lineColor: Int = Color.GRAY

    /**
     * 轴线的宽度(粗细)
     */
    @setparam:Px
    @setparam:FloatRange(from = 1.0)
    open var lineWidth: Float = 1f.px
        set(value) {
            if (value < 1f) {
                return
            }

            field = value
        }

    /**
     * 轴线样式
     */
    open var linePathEffect: PathEffect? = null

    /**
     * 轴上标签数量
     */
    @setparam:IntRange(from = 3)
    open var labelCount: Int = 5
        set(value) {
            if (field == value) {
                return
            }

            field = if (value < 3) {
                3
            } else {
                value
            }
        }

    /**
     * 标签值文本大小
     */
    @setparam:Px
    open var labelTextSize: Float = 24f.px

    /**
     * 标签值颜色
     */
    @setparam:ColorInt
    open var labelColor: Int = Color.BLACK

    /**
     * 标签绘制距离轴线偏移值
     */
    @setparam:Px
    open var labelOffsetAxis: Float = 5f.px

    /**
     * 标签值格式化
     */
    open var axisValueFormat: AxisValueFormat? = { it.toString() }

    /**
     * 应用其它轴配置数据
     */
    open fun apply(axis: Axis) {
        this.lineColor = axis.lineColor
        this.lineWidth = axis.lineWidth
        this.linePathEffect = axis.linePathEffect

        this.labelCount = axis.labelCount
        this.labelTextSize = axis.labelTextSize
        this.labelColor = axis.labelColor
        this.labelOffsetAxis = axis.labelOffsetAxis
        this.axisValueFormat = axis.axisValueFormat
    }
}

/**
 * 文本格式化
 */
typealias AxisValueFormat = (position: Int) -> String?